home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14060 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: solon.com!not-for-mail
  2. From: kanze@gabi-soft.fr (J. Kanze)
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated,hp.unix,comp.sys.hp.apps,comp.sys.hp.hpux
  4. Subject: Re: C coding problem
  5. Date: 11 Apr 1996 12:04:54 -0500
  6. Organization: GABI Software, Sarl.
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4kje3m$9ut@solutions.solon.com>
  10. References: <4j06na$808@solutions.solon.com> <4jttan$3gf@solutions.solon.com>
  11.     <4jv6st$crf@solutions.solon.com> <4k1qh3$5hn@solutions.solon.com>
  12. NNTP-Posting-Host: solutions.solon.com
  13.  
  14. In article <4kg8hu$ij7@solutions.solon.com>
  15. schwarz@mips.complang.tuwien.ac.at (Konrad Schwarz) writes:
  16.  
  17. |> |> What is obfuscation is using pointers when the original data is an array
  18. |> |> (or vice-versa).
  19.  
  20. |> In which situations would you use pointer arithmetic?
  21.  
  22. Explicitly, with the exception of ++ and -- (and maybe += and -=),
  23. fairly rarely.  (Implicitly, of course, everytime I write a[ i ]:-).)
  24. In general, when I use pointer arithmetic at all (including ++), it is
  25. because I am viewing the memory as some sort of a sequential file, with
  26. *p as a non-destructive peek operation, and *p ++ as a read.  In such
  27. cases, I would used *(p + 1) (rather than p[ 1 ]) to do look-ahead.  Off
  28. hand, the only instance of this that I can recall is in parsing
  29. character sets in regular expressions ([...]).  I have a bit of code
  30. that is basically:
  31.  
  32.     while ( *p != ']' && *p != '\0' )
  33.     {
  34.         if ( *(p + 1) == '-' && *(p + 2) != ']' )
  35.         {
  36.             /*  Process a range */
  37.             p += 3 ;
  38.         }
  39.         else
  40.         {
  41.             /*  Process a single character */
  42.             p ++ ;
  43.         }
  44.     }
  45.  
  46. I think that the key point is consistency in a given context.  If I'm
  47. calculating some complex integral value to use as an index, I'm not
  48. suddenly going to switch to pointer arithmetic.  In the above case, I am
  49. scanning a string, using p++ to advance.  So, IMHO, suddenly shifting to
  50. array notation locally would be confusing.
  51. -- 
  52. James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
  53. GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
  54. Conseils en informatique industrielle --
  55.                             -- Beratung in industrieller Datenverarbeitung
  56.